package zz.demo.springCloud.config.securityService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import zz.demo.springCloud.dao.UserDao;
import zz.demo.springCloud.entity.User;

/**
 * Created by zhangzheng on 2017-6-22.
 */
@Component
public class SecurityUserService implements UserDetailsService {

    @Autowired
    private UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userDao.findByUsername(username);
        if(user==null){
            throw new UsernameNotFoundException(username+" not found!");
        }
        SecurityUser securityUser=new SecurityUser(user);
        return securityUser;
    }


}
